#!/bin/bash
nArch="tp1"
nInArch="in.bin"
n2Arch="2.bin"
n16Arch="16.hex"
nTest16Arch="test_16.hex"
nTest2Arch="test_2.bin"

function bin_to_hex(){

hexdump -v -e '1/1 "%02x"' ${nInArch} > ${nTest16Arch}
./${nArch} -a encode -i ${nInArch} -o ${n16Arch}
}

function hex_to_bin(){
./${nArch} -a decode -i ${n16Arch} -o ${n2Arch}
}

function clean(){
rm $nInArch
rm $nTest16Arch; rm $n16Arch; rm $n2Arch;
}

# prueba 1
echo "Ejecutando prueba 1 (bin to hexa, no other options)"
echo -n "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\'()*+,-./:;<=>?@[]^_\`{|}~" > ${nInArch} 
bin_to_hex
#diff -c ${n16Arch} ${nTest16Arch}
DIFF=$(diff -c ${n16Arch} ${nTest16Arch}) 
if [ "$DIFF" = "" ]
then
echo "Prueba 1 OK"
else 
echo "Prueba 1 NO OK"
fi
#fin prueba 1


# prueba 2
echo "Ejecutando prueba 2 (hexa to bin, no other options)"
hex_to_bin
diff -B -c ${n2Arch} ${nInArch}
DIFF=$(diff -B -c ${n2Arch} ${nInArch}) 
if [ "$DIFF" = "" ]
then
echo "Prueba 2 OK"
else 
echo "Prueba 2 NO OK"
fi
# fin prueba 

clean

# prueba 3
echo "Ejecutando prueba 3 (bin to hexa, Archivo Vacio)"
echo -n "" > ${nInArch} 
bin_to_hex
DIFF=$(diff -c ${n16Arch} ${nTest16Arch}) 
if [ "$DIFF" = "" ]
then
echo "Prueba 3 OK"
else 
echo "Prueba 3 NO OK"
fi
# fin prueba

# prueba 4 
echo "Ejecutando prueba 4 (bin to hexa, Archivo Vacio)"
hex_to_bin
DIFF=$(diff -B -c ${n2Arch} ${nInArch}) 
if [ "$DIFF" = "" ]
then
echo "Prueba 4 OK"
else 
echo "Prueba 4 NO OK"
fi
#fin prueba  

clean

